﻿using System;
using System.Windows;
using System.Windows.Controls;
using CTS.App.Com.Domain.Helper;
using CTS.Com.Domain.Helper;
using CTS.Com.Domain.Logic;
using CTS.Com.Domain.Model;
using DevExpress.Xpf.Docking;

namespace CTS.App.Com.Domain.Controller
{
    /// <summary>
    /// UserControlBase
    /// </summary>
    public class UserControlBase : UserControl
    {
        protected void OpenWindow(Type type)
        {
            OpenWindow(type, null);
        }

        protected void OpenWindow(Type type, object param)
        {
            OpenWindow(type, param, false);
        }

        protected void OpenWindow(Type type, object param, bool isDialog)
        {
            FormHelper.OpenWindow(type, param, isDialog);
        }

        protected void CloseLayout(object control)
        {
            var dockLayoutManager = DockLayoutManager.GetDockLayoutManager(control as DependencyObject);
            var layout = DockLayoutManager.GetLayoutItem(control as DependencyObject);
            dockLayoutManager.DockController.Close(layout);
        }

        protected T Invoke<T>(IOperateLogic<T> logic, object param) where T : BasicResponse, new()
        {
            return FormHelper.Invoke<T>(logic, param);
        }

        protected T Invoke<T>(IOperateLogic<T> logic, object param, Type paramType) where T : BasicResponse, new()
        {
            return FormHelper.Invoke<T>(logic, param, paramType);
        }

        protected T CopyValue<T>(object data) where T : new()
        {
            return DataHelper.CopyObject<T>(data);
        }

        protected object GetProperty(string name)
        {
            return Application.Current.Properties[name];
        }

        protected ComboItem ToComboItem(object data)
        {
            return DataHelper.ToComboItem(data);
        }

        protected string ToString(bool? data)
        {
            return DataHelper.ToString(data);
        }

        protected string ToString(object data)
        {
            return Convert.ToString(data);
        }

        protected decimal ToDecimal(string data)
        {
            var value = DataHelper.ConvertInputNumber(data);
            return Convert.ToDecimal(value);
        }

        protected decimal ToDecimal(decimal? data)
        {
            return Convert.ToDecimal(data);
        }
    }
}